package cn.edu.lingnan.lsqn.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.cdahua.basic.dao.BaseDao;
import cn.edu.lingnan.lsqn.model.Candidate;
import cn.edu.lingnan.lsqn.model.CandidateType;

@Repository("candidateDao")
public class CandidateDao extends BaseDao<Candidate> implements ICandidateDao {

	@Override
	public void addVote(int id) {
		String sql = "update t_candidate set totalVote = totalVote+1 where id = "+id;
		getSession().createSQLQuery(sql).executeUpdate();
	}
	@Override
	public void cutVote(int id) {
		String sql = "update t_candidate set totalVote = totalVote-1 where id = "+id;
		getSession().createSQLQuery(sql).executeUpdate();
	}

	@Override
	public List<Candidate> listByCandidateType(CandidateType type) {
		String hql = "from Candidate c where c.candidateType.id = ?";
		return list(hql,type.getId());
	}

}
